/***************************************************************
 * @System            : 生鲜系统
 * @Content           : 继承 PanelControl，增加了边框功能 
 * @Author            : lijin  2018-11-13
 * @Modify            : 
 * @Version           : v1.0
 * @Copyright         : 宁波康铭泰克信息科技有限公司
 ***************************************************************/


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Comteck.Winforms.Controls {

  [ToolboxItem(true)]

  public partial class MyPanel : PanelControl {

    #region ctor

    public MyPanel() {
      InitializeComponent();

      this.DoubleBuffered = true;//设置本窗体
      SetStyle(ControlStyles.UserPaint, true);
      SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
      SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
    }

    public MyPanel(IContainer container) {
      container.Add(this);

      InitializeComponent();

      this.DoubleBuffered = true;//设置本窗体
      SetStyle(ControlStyles.UserPaint, true);
      SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
      SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
    }

    #endregion

    #region properties

    /// <summary>
    /// 
    /// </summary>
    protected override CreateParams CreateParams {
      get {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED 
        return cp;
      }
    }

    #endregion

    #region field

    private Color _BorderColor = Color.Black;

    [Browsable(true), Description("边框颜色"), Category("自定义分组")]
    public Color BorderColor {
      get { return _BorderColor; }
      set {
        _BorderColor = value;
        this.Invalidate();
      }
    }

    private int _BorderSize = 1;

    [Browsable(true), Description("边框粗细"), Category("自定义分组")]
    public int BorderSize {
      get { return _BorderSize; }
      set {
        _BorderSize = value;
        this.Invalidate();
      }
    }

    #endregion

    #region events

    /// <summary>
    /// 重写OnPaint方法
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPaint(PaintEventArgs e) {
      ControlPaint.DrawBorder(e.Graphics,
                      this.ClientRectangle,
                      this._BorderColor,
                      this._BorderSize,
                      ButtonBorderStyle.Solid,
                      this._BorderColor,
                      this._BorderSize,
                      ButtonBorderStyle.Solid,
                     this._BorderColor,
                      this._BorderSize,
                      ButtonBorderStyle.Solid,
                      this._BorderColor,
                      this._BorderSize,
                      ButtonBorderStyle.Solid);
    }

    #endregion

  }
}
